package com.maben.udp.test001;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.util.concurrent.atomic.AtomicLong;

/**
 * udp接收端
 */
public class UdpReceiver {
    private static AtomicLong num = new AtomicLong(0);
    public static void main(String[] args)throws Exception {
        DatagramSocket socket = new DatagramSocket(30003);
        byte[] buffer = new byte[1024];
        DatagramPacket p = new DatagramPacket(buffer,0,buffer.length);
        while(true){
            socket.receive(p);
            System.out.println("receive msg:"+num.addAndGet(1));
            System.out.println(new String(p.getData(),0,p.getLength()));
        }
    }
}
